<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>摸红天平游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            width: 100%;
            max-width: 900px;
            background-color: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            padding: 25px;
            margin-top: 20px;
            position: relative;
            overflow: hidden;
        }
        
        .container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 5px;
            background: linear-gradient(90deg, #d32f2f, #ff9800, #d32f2f);
        }
        
        h1 {
            text-align: center;
            color: #d32f2f;
            margin-bottom: 20px;
            font-size: 32px;
            text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
        }
        
        .game-info {
            text-align: center;
            margin-bottom: 30px;
            padding: 15px;
            background: linear-gradient(to right, #ffebee, #ffcdd2);
            border-radius: 10px;
            border: 2px solid #ffcdd2;
            box-shadow: 0 3px 10px rgba(0,0,0,0.05);
        }
        
        .difference {
            font-size: 26px;
            font-weight: bold;
            color: #d32f2f;
            margin: 10px 0;
        }
        
        .target {
            color: #666;
            font-size: 16px;
            font-weight: bold;
        }
        
        .scale-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 40px 0;
            position: relative;
            height: 200px;
        }
        
        .scale-side {
            flex: 1;
            text-align: center;
            padding: 0 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .scale-tray {
            width: 180px;
            height: 80px;
            background: linear-gradient(to bottom, #e0e0e0, #bdbdbd);
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
            box-shadow: inset 0 5px 10px rgba(0,0,0,0.1), 0 5px 15px rgba(0,0,0,0.1);
            border: 2px solid #9e9e9e;
        }
        
        .scale-tray::after {
            content: '';
            position: absolute;
            top: -15px;
            width: 160px;
            height: 15px;
            background: #8d6e63;
            border-radius: 5px 5px 0 0;
        }
        
        .scale-number {
            font-size: 36px;
            font-weight: bold;
            color: #333;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
        }
        
        .scale-beam {
            width: 100%;
            height: 12px;
            background: linear-gradient(to bottom, #5d4037, #3e2723);
            position: absolute;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
            z-index: 1;
            box-shadow: 0 3px 10px rgba(0,0,0,0.2);
        }
        
        .scale-beam::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 20px;
            height: 60px;
            background: linear-gradient(to bottom, #5d4037, #3e2723);
            border-radius: 5px;
            z-index: 2;
        }
        
        .scale-label {
            margin-top: 15px;
            font-weight: bold;
            color: #555;
            font-size: 16px;
        }
        
        .input-section {
            display: flex;
            justify-content: space-between;
            margin-top: 30px;
        }
        
        .input-group {
            flex: 1;
            padding: 0 20px;
        }
        
        .input-group h3 {
            margin-bottom: 12px;
            color: #333;
            font-size: 18px;
            border-bottom: 2px solid #d32f2f;
            padding-bottom: 5px;
        }
        
        .input-container {
            display: flex;
            margin-bottom: 15px;
        }
        
        input {
            flex: 1;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        input:focus {
            border-color: #d32f2f;
            outline: none;
        }
        
        button {
            padding: 12px 20px;
            background: linear-gradient(to bottom, #d32f2f, #b71c1c);
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            margin-left: 10px;
            transition: all 0.3s;
            box-shadow: 0 3px 5px rgba(0,0,0,0.2);
        }
        
        button:hover {
            background: linear-gradient(to bottom, #b71c1c, #8e0000);
            transform: translateY(-2px);
            box-shadow: 0 5px 8px rgba(0,0,0,0.2);
        }
        
        button:active {
            transform: translateY(0);
            box-shadow: 0 2px 3px rgba(0,0,0,0.2);
        }
        
        .range-info {
            color: #666;
            font-size: 14px;
            margin-top: 5px;
            font-style: italic;
        }
        
        .game-status {
            text-align: center;
            margin-top: 25px;
            padding: 15px;
            border-radius: 10px;
            font-size: 18px;
            font-weight: bold;
            transition: all 0.5s;
        }
        
        .win {
            background: linear-gradient(to right, #e8f5e9, #c8e6c9);
            color: #2e7d32;
            border: 2px solid #4caf50;
            box-shadow: 0 3px 10px rgba(76,175,80,0.3);
        }
        
        .lose {
            background: linear-gradient(to right, #ffebee, #ffcdd2);
            color: #d32f2f;
            border: 2px solid #f44336;
        }
        
        .instructions {
            margin-top: 30px;
            padding: 20px;
            background: linear-gradient(to right, #f9f9f9, #f0f0f0);
            border-radius: 10px;
            border-left: 5px solid #d32f2f;
            box-shadow: 0 3px 10px rgba(0,0,0,0.05);
        }
        
        .instructions h3 {
            margin-bottom: 12px;
            color: #d32f2f;
            font-size: 20px;
        }
        
        .instructions ul {
            padding-left: 20px;
        }
        
        .instructions li {
            margin-bottom: 8px;
            line-height: 1.5;
        }
        
        .reset-container {
            text-align: center;
            margin-top: 20px;
        }
        
        #reset-button {
            background: linear-gradient(to bottom, #ff9800, #f57c00);
            padding: 12px 30px;
            font-size: 18px;
            margin-left: 0;
        }
        
        #reset-button:hover {
            background: linear-gradient(to bottom, #f57c00, #e65100);
        }
        
        .tray-chain {
            width: 4px;
            height: 40px;
            background: #5d4037;
            margin: 0 auto;
            position: relative;
            z-index: 2;
        }
        
        @media (max-width: 768px) {
            .input-section {
                flex-direction: column;
            }
            
            .input-group {
                margin-bottom: 20px;
            }
            
            .scale-tray {
                width: 140px;
            }
            
            .scale-tray::after {
                width: 120px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>摸红天平</h1>
        
        <div class="game-info">
            <p>让天平两边的数字相差小于500000即可获胜！</p>
            <div class="difference">当前差值：<span id="difference">0</span></div>
            <div class="target">目标：小于500,000</div>
        </div>
        
        <div class="scale-container">
            <div class="scale-side">
                <div class="scale-tray">
                    <div class="scale-number" id="left-number">0</div>
                </div>
                <div class="tray-chain"></div>
                <div class="scale-label">左边数字（< 1,000,000）</div>
            </div>
            
            <div class="scale-beam"></div>
            
            <div class="scale-side">
                <div class="scale-tray">
                    <div class="scale-number" id="right-number">0</div>
                </div>
                <div class="tray-chain"></div>
                <div class="scale-label">右边数字（≥ 1,000,000）</div>
            </div>
        </div>
        
        <div class="input-section">
            <div class="input-group">
                <h3>累加到左边</h3>
                <div class="input-container">
                    <input type="number" id="left-input" placeholder="输入数字" min="0" max="999999">
                    <button id="left-add">添加</button>
                </div>
                <div class="range-info">范围：0 - 999,999</div>
            </div>
            
            <div class="input-group">
                <h3>累加到右边</h3>
                <div class="input-container">
                    <input type="number" id="right-input" placeholder="输入数字" min="1000000">
                    <button id="right-add">添加</button>
                </div>
                <div class="range-info">范围：1,000,000 以上</div>
            </div>
        </div>
        
        <div class="game-status" id="game-status"></div>
        
        <div class="reset-container">
            <button id="reset-button">重置游戏</button>
        </div>
        
        <div class="instructions">
            <h3>游戏说明</h3>
            <ul>
                <li>目标：使天平左右两侧数字的差值小于500,000</li>
                <li>左侧只能添加0-999,999之间的数字</li>
                <li>右侧只能添加1,000,000以上的数字</li>
                <li>输入数字后点击"添加"按钮或按回车键累加到相应侧</li>
                <li>差值实时显示在顶部</li>
                <li>点击"重置游戏"按钮可以重新开始</li>
            </ul>
        </div>
    </div>

    <script>
        // 游戏状态变量
        let leftNumber = 0;
        let rightNumber = 0;
        
        // 获取DOM元素
        const leftNumberElement = document.getElementById('left-number');
        const rightNumberElement = document.getElementById('right-number');
        const differenceElement = document.getElementById('difference');
        const gameStatusElement = document.getElementById('game-status');
        const leftInput = document.getElementById('left-input');
        const rightInput = document.getElementById('right-input');
        const leftAddButton = document.getElementById('left-add');
        const rightAddButton = document.getElementById('right-add');
        const resetButton = document.getElementById('reset-button');
        
        // 更新显示的函数
        function updateDisplay() {
            leftNumberElement.textContent = leftNumber.toLocaleString();
            rightNumberElement.textContent = rightNumber.toLocaleString();
            
            const difference = Math.abs(leftNumber - rightNumber);
            differenceElement.textContent = difference.toLocaleString();
            
            // 更新游戏状态
            if (difference < 500000) {
                gameStatusElement.textContent = "恭喜！你赢了！天平两边差值小于500,000！";
                gameStatusElement.className = "game-status win";
            } else {
                gameStatusElement.textContent = "继续努力，让差值小于500,000！";
                gameStatusElement.className = "game-status lose";
            }
            
            // 更新天平倾斜效果
            updateScaleTilt();
        }
        
        // 更新天平倾斜效果
        function updateScaleTilt() {
            const scaleBeam = document.querySelector('.scale-beam');
            const leftTray = document.querySelector('.scale-side:first-child .scale-tray');
            const rightTray = document.querySelector('.scale-side:last-child .scale-tray');
            
            const difference = leftNumber - rightNumber;
            let tilt = 0;
            
            if (difference !== 0) {
                // 计算倾斜角度，限制在-5到5度之间
                tilt = Math.max(-5, Math.min(5, difference / 10000000 * 5));
            }
            
            scaleBeam.style.transform = `translateY(-50%) rotate(${tilt}deg)`;
            
            // 轻微调整托盘位置以增强视觉效果
            leftTray.style.transform = `translateY(${tilt * 2}px)`;
            rightTray.style.transform = `translateY(${-tilt * 2}px)`;
        }
        
        // 添加到左侧的函数
        function addToLeft() {
            const value = parseInt(leftInput.value);
            
            if (isNaN(value) || value < 0 || value > 999999) {
                alert("请输入0-999,999之间的数字！");
                return;
            }
            
            leftNumber += value;
            leftInput.value = '';
            updateDisplay();
        }
        
        // 添加到右侧的函数
        function addToRight() {
            const value = parseInt(rightInput.value);
            
            if (isNaN(value) || value < 1000000) {
                alert("请输入1,000,000以上的数字！");
                return;
            }
            
            rightNumber += value;
            rightInput.value = '';
            updateDisplay();
        }
        
        // 重置游戏
        function resetGame() {
            leftNumber = 0;
            rightNumber = 0;
            leftInput.value = '';
            rightInput.value = '';
            updateDisplay();
        }
        
        // 事件监听
        leftAddButton.addEventListener('click', addToLeft);
        rightAddButton.addEventListener('click', addToRight);
        resetButton.addEventListener('click', resetGame);
        
        leftInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                addToLeft();
            }
        });
        
        rightInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                addToRight();
            }
        });
        
        // 初始化显示
        updateDisplay();
    </script>
</body>
</html>